// 
// Decompiled by Procyon v0.5.36
// 

package com.akamai.botman;

import android.os.*;
import android.hardware.*;
import android.util.*;
import java.util.*;
import java.util.concurrent.*;

public final class p implements java.util.Observer
{
    com.akamai.botman.o a;
    boolean b;
    long c;
    public java.util.ArrayList<com.akamai.botman.n> d;
    private java.util.concurrent.Future<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>> e;
    
    p() {
        this.a = null;
        this.b = false;
        this.c = 0L;
        this.d = new java.util.ArrayList<com.akamai.botman.n>();
        this.e = null;
    }
    
    public final void a() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        if (!this.a.a()) {
            com.akamai.botman.al.c("OrientationManager", "Orientation listener registration failed", new java.lang.Throwable[0]);
            return;
        }
        this.b = true;
        this.a.addObserver(this);
    }
    
    public final void b() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.a.b();
        this.a.deleteObservers();
    }
    
    public final void c() {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.c = android.os.SystemClock.uptimeMillis();
        this.d.clear();
        this.f();
    }
    
    public final com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long> d() {
        if (this.e != null) {
            try {
                return this.e.get();
            }
            catch (java.lang.InterruptedException ex) {
                com.akamai.botman.al.b("OrientationManager", "Failed to get orientation data: " + ex.getMessage(), new java.lang.Throwable[0]);
            }
            catch (java.util.concurrent.ExecutionException ex2) {
                com.akamai.botman.al.b("OrientationManager", "Failed to get orientation data: " + ex2.getMessage(), new java.lang.Throwable[0]);
            }
        }
        return this.e();
    }
    
    private com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long> e() {
        if (this.d.size() > 1) {
            try {
                final java.lang.Throwable[] array = new java.lang.Throwable[0];
                final long uptimeMillis = android.os.SystemClock.uptimeMillis();
                final int n;
                final float[] array2 = new float[n = (int)com.akamai.botman.ak.a(this.d.size())];
                final float[] array3 = new float[n];
                final float[] array4 = new float[n];
                final float[] array5 = new float[n];
                long n2 = this.c;
                int n3 = 0;
                for (final com.akamai.botman.n n4 : this.d) {
                    final float[] array6 = new float[9];
                    if (android.hardware.SensorManager.getRotationMatrix(array6, new float[9], n4.a, n4.b)) {
                        final float[] array7 = new float[3];
                        android.hardware.SensorManager.getOrientation(array6, array7);
                        final float n5 = (float)java.lang.Math.toDegrees(array7[0]);
                        final float n6 = (float)java.lang.Math.toDegrees(array7[1]);
                        final float n7 = (float)java.lang.Math.toDegrees(array7[2]);
                        float n8;
                        if ((n8 = n5 * -1.0f) < 0.0f) {
                            n8 += 360.0f;
                        }
                        final float n9 = n6 * -1.0f;
                        array2[n3] = n8;
                        array3[n3] = n9;
                        array4[n3] = n7;
                        array5[n3] = (float)java.lang.Math.max(0L, n4.c - n2);
                        new java.lang.StringBuilder("Orientation fields: ").append(array2[n3]).append(",").append(array3[n3]).append(",").append(array4[n3]).append(" / time(ms): ").append(android.os.SystemClock.uptimeMillis() - n4.c);
                        final java.lang.Throwable[] array8 = new java.lang.Throwable[0];
                    }
                    else {
                        array2[n3] = 0.0f;
                        array4[n3] = (array3[n3] = 0.0f);
                        com.akamai.botman.al.b("OrientationManager", "Failed to get rotation matrix", new java.lang.Throwable[0]);
                    }
                    n2 = n4.c;
                    if (++n3 >= n) {
                        break;
                    }
                }
                final android.util.Pair<java.lang.String, java.lang.Long> a = com.akamai.botman.ah.a(array2, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a2 = com.akamai.botman.ah.a(array3, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a3 = com.akamai.botman.ah.a(array4, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a4 = com.akamai.botman.ah.a(array5, 0.0f);
                final java.lang.String string = (java.lang.String)a.first + ":" + (java.lang.String)a2.first + ":" + (java.lang.String)a3.first;
                final long n10 = (long)a.second + (long)a2.second + (long)a3.second;
                final com.akamai.botman.m m = new com.akamai.botman.m();
                java.lang.String string2 = "";
                long n11 = this.c;
                int n12 = 0;
                for (final com.akamai.botman.n n13 : this.d) {
                    final com.akamai.botman.m i = m;
                    final com.akamai.botman.n n14 = n13;
                    final long n15 = n11;
                    final com.akamai.botman.n n16 = n14;
                    final com.akamai.botman.m j = i;
                    final float[] a5 = n16.a;
                    final float[] b = n16.b;
                    final float[] array9 = new float[9];
                    android.util.Pair pair;
                    if (!android.hardware.SensorManager.getRotationMatrix(array9, new float[9], a5, b)) {
                        com.akamai.botman.al.b("OrientationFormatter", "Failed to get rotation matrix", new java.lang.Throwable[0]);
                        pair = new android.util.Pair((java.lang.Object)"", (java.lang.Object)0L);
                    }
                    else {
                        final float[] array10 = new float[3];
                        android.hardware.SensorManager.getOrientation(array9, array10);
                        final float n17 = (float)java.lang.Math.toDegrees(array10[0]);
                        final float n18 = (float)java.lang.Math.toDegrees(array10[1]);
                        final float n19 = (float)java.lang.Math.toDegrees(array10[2]);
                        float n20;
                        if ((n20 = n17 * -1.0f) < 0.0f) {
                            n20 += 360.0f;
                        }
                        final java.lang.String format = j.a.format(n20);
                        final java.lang.String format2 = j.a.format(n18 * -1.0f);
                        final java.lang.String format3 = j.a.format(n19);
                        long n21;
                        if ((n21 = n16.c - n15) < 0L) {
                            n21 = 0L;
                        }
                        final java.lang.String string3 = n21 + "," + format + "," + format2 + "," + format3 + "," + n16.d + ";";
                        final long n22 = n21 + java.lang.Math.round((java.lang.Float.parseFloat(format) + java.lang.Float.parseFloat(format2) + java.lang.Float.parseFloat(format3)) * 100.0f);
                        new java.lang.StringBuilder("Orientation string ").append(string3).append(" time(ms): ").append(android.os.SystemClock.uptimeMillis() - n16.c);
                        final java.lang.Throwable[] array11 = new java.lang.Throwable[0];
                        pair = new android.util.Pair((java.lang.Object)string3, (java.lang.Object)n22);
                    }
                    string2 += (java.lang.String)pair.first;
                    n11 = n13.c;
                    if (++n12 >= 10) {
                        break;
                    }
                }
                final com.akamai.botman.am am = new com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>(string2, string, a4.first);
                final long n23 = android.os.SystemClock.uptimeMillis() - uptimeMillis;
                com.akamai.botman.al.a("OrientationManager", "Orientation Count SDCalc-Time: " + n + "/" + this.d.size(), new java.lang.Throwable[0]);
                com.akamai.botman.al.a("OrientationManager", "Orientation SDCalc-Time: " + n23 + "ms", new java.lang.Throwable[0]);
                return new com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>(am, n10, (long)n);
            }
            catch (java.lang.Exception ex) {
                com.akamai.botman.al.b("OrientationManager", "Exception in getting orientation events", ex);
                com.akamai.botman.f.a(ex);
            }
        }
        return new com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>(new com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>("", "", ""), 0L, 0L);
    }
    
    @java.lang.Override
    public final void update(final java.util.Observable observable, java.lang.Object data) {
        try {
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            if (data == null) {
                return;
            }
            if (this.d.size() >= 128) {
                this.b();
                this.f();
                data = java.util.concurrent.Executors.newFixedThreadPool(1);
                this.e = ((java.util.concurrent.ExecutorService)data).<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>submit((java.util.concurrent.Callable<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>)new com.akamai.botman.p.a());
                return;
            }
            this.d.add((com.akamai.botman.n)data);
        }
        catch (java.lang.Exception ex) {
            com.akamai.botman.al.b("OrientationManager", "Exception in processing orientation event", ex);
            com.akamai.botman.f.a(ex);
        }
    }
    
    private void f() {
        if (this.e != null) {
            if (!this.e.isCancelled() && !this.e.isDone()) {
                this.e.cancel(true);
            }
            this.e = null;
        }
    }
    
    final class a implements java.util.concurrent.Callable<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>
    {
    }
}
